package com.aaa.sbms.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @FileName:TrainerDao
 * @Description:
 * @Author :99728
 * @Date: 2020/6/11 20:17
 * @Version:1.0.0
 */
public interface TrainerDao {
    /**
     * 培训师列表
     * @return
     */
    @Select("<script>select trainerid,trainername,photopath,email,phone,coursename from trainer <where> "+
            "<if test=\"trainerid!=null and trainerid!=''\"> and trainerid=#{trainerid}</if>" +
            "<if test=\"trainerName!=null and trainerName!=''\"> and trainername like concat('%',#{trainername},'%')</if>" +
            "</where>" +
            "</script>")
    List<Map> getlist(Map map);

    /**
     * 分页带参查询培训管理列表
     */
    @Select("<script>select * from trainer"+
            "<where>" +
            " <if test='trainername!=null'> and trainername like '%${trainername}%' </if>"+
            " <if test=\"trainerid!=null and trainerid !=''\"> and trainerid =#{trainerid} </if>"+
            "</where>order by trainerid \n" +
            "limit #{begin},#{pageSize}</script>")
    List<Map> getPage(Map map);

    /**
     * 带参总条数查询培训管理
     * @param map
     * @return
     */
    @Select("<script>select count(*) from trainer  " +
            "<where>" +
            " <if test='trainerName!=null'> and trainerName like '%${trainerName}%' </if>"+
            " <if test=\"trainerId!=null and trainerId !=''\"> and trainerId =#{trainerId} </if>"+
            "</where></script>")
    int getPageCount(Map map);

    /**
     * 下拉 课程名称查询
     * @param map
     * @return
     */
    @Select("select courseid,coursename from course")
    List<Map> getCourseName(Map map);

    /**
     * 根据Id查寻信息
     * @param trainerId
     * @return
     */
    @Select("select * from trainer where trainerId = #{trainerId}")
    Map onelist(int trainerId);

    /**
     * 添加
     * @param map
     * @return
     */
    @Insert("insert into trainer (trainerid,trainername,photopath,email,phone,coursename) values" +
            "(#{trainerid},#{trainername},#{photopath},#{email},#{phone},#{coursename})")
    int add(Map map);

    /**
     * 更新
     * @param map
     * @return
     */
    @Update("update trainer set trainername=#{trainername},photopath=#{photopath},email=#{email},phone=#{phone},coursename=#{coursename} " +
            "where trainerid=#{trainerid}")
    int update(Map map);

    /**
     * 删除该ID关联的信息
     * @param trainerId
     * @return
     */
    @Delete("delete from trainer where trainerId=#{trainerId}")
    int delete(int trainerId);
}
